Creating
a gambas2
program,
step by step, a telephone index
From : http://listingambas.blogspot.com/2011/06/modulo-archivo-leer.html
Module File:
Read
We can read our data .... our
agenda is almost functional
Well, once we save our data, we need to read it. As usual, we will be organized with the module "File" and create the
following subroutine:
PUBLIC SUBopenData ( OPTIONAL sRoot
AS
String
)
DIM
a AS
Integer 'data group count
DIM
b as
integer 'data count
DIM Endofline
AS
String[]
DIM
arr_string
AS
String[]
DIM
data_number
AS
Integer
Endofline
=
"|"
IF sRoot = ""
THEN
Dialog. Title
=
"Select a data file listin"
Dialog. Filter
=
[ "*.
lis" , "Listin Data"
]
IF
NOT
Dialog.OpenFile()
THEN
sRoot =
Dialog.Path
ELSE
RETURN
ENDIF
ENDIF
arr_string
=
Split
(File.Load(sRoot), Endofline)
IF
arr_string[0] <> "v0.0.1" THEN
'version
number is not compatible with this program version, quit the procedure
Message. Error
("Error:
Incompatible data version")
GOTO EndRead
ENDIF
data_number =
arr_string[ 2
] '
arr_string[1] holds the name of the program we made
b
=
2
'Resize
the data ....
var. id
. Resize
(data_number)
var. dni
. Resize
(data_number)
var. name
. Resize
(data_number)
var. surname
. Resize
(data_number)
var. company
. Resize
(data_number)
var. position
. Resize
(data_number)
var. tel_company
. Resize
(data_number)
var. tel_private
. Resize
(data_number)
var. fax
. Resize
(data_number)
var. mobile_company
. Resize
(data_number)
var. mobile_private
. Resize
(data_number)
var. page
. Resize
(data_number)
var. photo
. Resize
(data_number)
var. address
. Resize
(data_number)
var. comments
. Resize
(data_number)
var. data_date
. Resize
(data_number)
var. mail . Resize
(data_number)
'Read
data
for a = 0 to data_number - 1
b
+
= 1
var. id
[a] =
arr_string [b]
b +
= 1
var. dni
[a] =
arr_string [b]
b +
= 1
var. name
[a] =
arr_string [b]
b +
= 1
var. surname
[a] =
arr_string [b]
b +
= 1
var. company
[a] =
arr_string [b]
b +
= 1
var. position
[a] =
arr_string [b]
b +
= 1
var. tel_company
[a] =
arr_string [b]
b +
= 1
var. tel_private
[a] =
arr_string [b]
b +
= 1
var. fax
[a] =
arr_string [b]
b +
= 1
var. mobile_company
[a] =
arr_string [b]
b +
= 1
var. mobile_private
[a] =
arr_string [b]
b +
= 1
var. page
[a] =
arr_string [b]
b +
= 1
var. photo
[a] =
arr_string [b]
b +
= 1
var. address
[a] =
arr_string [b]
b +
= 1
var. comments
[a] =
arr_string [b]
b +
= 1
var. data_date
[a] =
arr_string [b]
b +
= 1
var. mail
[a] =
arr_string [b]
NEXT
title.
fill
()
ENDIF
endread:
END
Command Split:
It can create an array from a string or a file
(file.load (Dialog.Path)
when the elements are separated by a specific character (in our case the
"EndOfLine")
arr_string = Split (File.LOAD (Dialog.Path) EndOfLine)
|
Then, in the form FMAIN
, we add the following code to the Menu File / Open_click
PUBLIC SUB Open_Click ()
file. openData ()
END